<template>
  <div>
    <div ref="mychart" style="width: 100%; height: 400px"></div>
  </div>
</template>

<script>
import * as echarts from "echarts";
export default {
  data() {
    return {
      arr: {
        xAxis: {
          type: "category",
          data: ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"],
        },
        yAxis: {
          type: "value",
        },
        series: [
          {
            data: [820, 932, 901, 934, 1290, 1330, 1320],
            type: "line",
            smooth: true,
          },
        ],
      },
    };
  },
  mounted() {
    this.getlist();
    window.addEventListener("resize", this.mychart.resize);
  },
  methods: {
    getlist() {
      //1.获取dom
      const chartDom = this.$refs.mychart;
      //2.初始化
      this.mychart = echarts.init(chartDom);

      //   配置图表数据
      const option = this.arr;

      //4.渲染生成图表
      this.mychart.setOption(option);
    },
  },
};
</script>
